<template>
  <el-dialog title="发送邮件" :visible.sync="visibleCurrent" width="50%">
    <el-form :model="form" :rules="rules" ref="form" label-width="100px">
      <el-form-item label="物流单号" prop="trackingNumber">
        <el-input v-model="form.trackingNumber"></el-input>
      </el-form-item>
      <el-form-item label="备注" prop="remarks">
        <el-input type="textarea" v-model="form.remarks" :rows="4"></el-input>
      </el-form-item>
      <el-form-item label="收件邮箱" prop="recipientEmail">
        <el-input v-model="form.recipientEmail"></el-input>
      </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visibleCurrent = false">取消</el-button>
      <el-button type="primary" @click="submitForm" :loading="loading"
        >发送</el-button
      >
    </span>
  </el-dialog>
</template>
  
  <script>
export default {
  props: {
    visible: {
      type: Boolean,
      default: false,
    },
  },
  data() {
    return {
      form: {
        trackingNumber: "",
        remarks: "",
        recipientEmail: "",
      },
      rules: {
        trackingNumber: [
          { required: true, message: "请输入物流单号", trigger: "blur" },
        ],
        recipientEmail: [
          { required: true, message: "请输入收件邮箱", trigger: "blur" },
          {
            type: "email",
            message: "请输入正确的邮箱地址",
            trigger: ["blur", "change"],
          },
        ],
      },
      loading: false,
      visibleCurrent: false,
    };
  },
  watch: {
    visible(val) {
      this.visibleCurrent = val;
      if (!val) {
        this.$refs.form.resetFields();
      }
    },
  },
  methods: {
    submitForm() {
      this.$refs.form.validate((valid) => {
        if (valid) {
          this.$emit("submit", this.form);
          this.visibleCurrent = true;
        }
      });
    },
  },
};
</script>